package com.asset.dispoal.user;

import com.asset.dispoal.user.api.UserService;
import com.asset.dispoal.user.dto.BsLawyerAddRequest;
import com.asset.dispoal.user.dto.BsLawyerCourtRequest;
import com.asset.dispoal.user.dto.BsLawyerResponse;
import com.asset.dispoal.user.dto.BsLawyerUpdateRequest;
import com.asset.dispoal.user.dto.UserRequest;
import com.asset.dispoal.user.dto.UserResetPwdRequest;
import com.asset.dispoal.user.dto.UserResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

/**
 * @author qr
 * @date 2022/1/21$
 */
@RestController
@Api(value = "用户管理", tags = "用户管理")
@RequestMapping("sys/user")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/login")
    @ApiOperation(value = "登录", notes = "登录")
    public Result<UserResponse> login(UserRequest request) {
        return userService.login(request);
    }

    @Deprecated
    @GetMapping("/queryPage")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<PageVO<UserResponse>> queryPage(UserRequest request) {
        return userService.queryPage(request);
    }

    @Deprecated
    @PostMapping("/resetPwd")
    @ApiOperation(value = "重置密码", notes = "重置密码")
    public Result resetPwd(@RequestBody UserResetPwdRequest request) {
        return userService.resetPwd(request);
    }


    @Permission(code = "systemCompanyUser:password")
    @PostMapping("/resetSystemCompanyUserPwd")
    @ApiOperation(value = "重置公司用户密码", notes = "重置公司用户密码")
    public Result resetSystemCompanyUserPwd(@RequestBody UserResetPwdRequest request) {
        return userService.resetPwd(request);
    }

    @Permission(code = "systemCompanyUser:query", param = "t.create_user")
    @GetMapping("/systemCompanyUserPage")
    @ApiOperation(value = "公司用户分页查询", notes = "公司用户分页查询")
    public Result<PageVO<UserResponse>> systemCompanyUser(UserRequest request) {
        return userService.queryPage(request);
    }


    @Permission(code = "systemCompanyUser:update")
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "修改")
    public Result update(@RequestBody UserRequest userRequest) {
        return userService.update(userRequest);
    }


    @Permission(code = "systemCompanyUser:add")
    @PostMapping("/register")
    @ApiOperation(value = "添加注册", notes = "添加注册")
    public Result register(@RequestBody UserRequest userRequest) {
        return userService.register(userRequest);
    }

    @Permission(code = "systemLawyerUser:password")
    @PostMapping("/resetSystemLawyerUserUserPwd")
    @ApiOperation(value = "重置律师用户密码", notes = "重置律师用户密码")
    public Result resetSystemLawyerUserUserPwd(@RequestBody UserResetPwdRequest request) {
        return userService.resetPwd(request);
    }

    @Permission(code = "systemLawyerUser:query", param = "t.create_user")
    @GetMapping("/systemLawyerUserPage")
    @ApiOperation(value = "律所用户分页查询", notes = "律所用户分页查询")
    public Result<PageVO<UserResponse>> systemLawyerUser(UserRequest request) {
        return userService.queryPage(request);
    }

    @Permission(code = "systemLawyerUser:add")
    @PostMapping("/insertLawyer")
    @ApiOperation(value = "添加律师信息", notes = "添加律师信息")
    public Result insertLawyer(@RequestBody BsLawyerAddRequest bsLawyerRequest) {
        return userService.insertLawyer(bsLawyerRequest);
    }


    @Permission(code = "systemLawyerUser:update")
    @PostMapping("/updateLawyer")
    @ApiOperation(value = "修改律师信息", notes = "修改律师信息")
    public Result updateLawyer(@RequestBody BsLawyerUpdateRequest bsLawyerRequest) {
        return userService.updateLawyer(bsLawyerRequest);
    }

    @Permission(code = "systemLawyerUser:query")
    @GetMapping("/queryLawyerDetail")
    @ApiOperation(value = "根据用户id查询律师信息", notes = "根据用户id查询律师信息")
    public Result<BsLawyerResponse> queryLawyerDetail(String userId) {
        return userService.queryLawyerDetail(userId);
    }

    @Permission(code = "systemLawyerUser:query")
    @GetMapping("/queryLawyerByCourt")
    @ApiOperation(value = "根据法院获取律师信息", notes = "根据法院获取律师信息")
    public Result<PageVO<BsLawyerResponse>> queryLawyerByCourt(BsLawyerCourtRequest request) {
        return userService.queryLawyerByCourt(request);
    }
}